package com.ruoyi.system.task;


import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.sz.SzPersonal;
import com.ruoyi.system.domain.sz.SzPersonalRecord;
import com.ruoyi.system.mapper.sz.SzPersonalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static com.ruoyi.common.constant.TimeLineConstants.*;
import static com.ruoyi.common.constant.TimeLineConstants.SZ_CLASSIFY_GRADE_3;

@Service("szPersonalTask")
public class SzPersonalTask {
    @Autowired
    private SzPersonalMapper szPersonalMapper;
    public void rySzPoliticalReview(){
        SzPersonal szPersonal = new SzPersonal();
        szPersonal.setStatus(PERSONAL_STATUS_3);
        List<SzPersonal> szPersonals = szPersonalMapper.selectSzPersonalList(szPersonal);
        List<SzPersonal> collect = szPersonals.stream().filter(p -> StringUtils.isBlank(p.getPoliticType()) && isPolitic(p)).map(p -> {
            p.setPoliticType(POLITIC_TYPE_1);
            return p;
        }).collect(Collectors.toList());
        if(null != collect && collect.size() > 0){
            szPersonalMapper.batchUpdatePersonal(collect);
        }
    }

    /**
     * 当前时间-上岗时间（状态=在岗）核心3年，重要，一般的5年
     * @param szPersonal
     * @return
     */
    public boolean isPolitic(SzPersonal szPersonal){
        boolean flag = false;
        SzPersonalRecord szPersonalRecord = szPersonal.getSzPersonalRecord();
        if(null != szPersonalRecord){
            if(SZ_CLASSIFY_GRADE_1.equals(szPersonalRecord.getSecurityLevel()) || SZ_CLASSIFY_GRADE_2.equals(szPersonalRecord.getSecurityLevel())){
                int distanceYear = DateUtils.getDistanceYear(szPersonalRecord.getOnJobDate());
                if(5 <= distanceYear){
                    flag = true;
                }
            }else if(SZ_CLASSIFY_GRADE_3.equals(szPersonalRecord.getSecurityLevel())){
                int distanceYear = DateUtils.getDistanceYear(szPersonalRecord.getOnJobDate());
                if(3 <= distanceYear){
                    flag = true;
                }
            }
        }
        return flag;
    }

    public static void main(String[] args) {

        java.util.UUID uuid1 = java.util.UUID.randomUUID();

        System.out.println(uuid1);
    }
}
